import configparser
import os,sys


class PATH():
    """参数化路径方法"""
    def __init__(self):
        dir = os.path.dirname
        cur_path_Z = dir(dir(os.path.realpath(__file__)))                 # 获取顶层目录project
        sys.path.append(cur_path_Z)
        # print("顶层目录为：",cur_path_Z)
        os.chdir(cur_path_Z)
        self.top_path = cur_path_Z
        # print("cur_path_Z:",cur_path_Z)
        # print("os.getcwd():",os.getcwd())

    def get_top_path(self):
        top_path = self.pathSeparator(self.top_path)
        return top_path

    def get_top_dir(self):
        """获取顶层目录名，去除路径的目录名"""
        top_dir = os.path.split(self.top_path)[1]
        return top_dir

    def get_foder_path(self):
        foder_path = os.getcwd()
        return foder_path

    def path_join(self,dir):
        """ 路径拼接，【注】：传入dir时，最左边不能加斜线。"""
        f_dir = os.path.join(self.top_path,dir)
        f_dir = self.pathSeparator(f_dir)
        return f_dir

    def py_path(self):
        python_path = sys.path
        return python_path

    def path_add(self,dir=None):
        f_dir_add = self.path_join(dir=dir)
        sys.path.append(f_dir_add)
        return f_dir_add

    def create_path(self,dir=None):
        curPath = self.path_join(dir=dir)            # 目录拼接，添加一个与当前执行文件平级的目录
        # print(curPath)

        if os.path.exists(curPath):                  # 判断目录是否存在,不存在则创建目录curPath
            print("目录存在,不用创建")
        else:
            os.mkdir(curPath)
        return curPath

    # def get_dbConfPath(self):
    #     """ 获取数据库配置文件路径 ，配置文件：database.ini """
    #     dbPath_t = self.path_join("data\config/database.ini")
    #     dbPath = self.pathSeparator(dbPath_t)
    #     return dbPath

    def get_userFilePath(self,paths):
        """
        获取指定件路径
        :param paths : 相对路径，不包含根路径。 示例： "data\config/userHead.yaml"
        """
        dbPath_t = self.path_join(paths)
        dbPath = self.pathSeparator(dbPath_t)
        return dbPath

    def get_reportPath(self):
        """ 获取测试报告路径 """
        dbPath_t = self.path_join("data\m_outReport/report.html")
        dbPath = self.pathSeparator(dbPath_t)
        return dbPath

    def get_reportLog(self):
        """ 获取测试报告日志 """
        dbPath_t = self.path_join("data\m_outReport/report.log")
        dbPath = self.pathSeparator(dbPath_t)
        return dbPath

    def pathSeparator(self,actualpath):
        """
        将路径转换为当前环境的路径分隔符
        :param: actualpath 传入 真实的路径
        :return: 与当前系统匹配的路径
        """
        return actualpath.replace("\\",os.path.sep).replace("/",os.path.sep)


pathConf = PATH()



if __name__ == "__main__":
    # print("111",top_path)
    pass
    # pathConf = PATH()
    # print(pathConf.get_userFilePath("data/a_envData/env.yaml"))
